package de.tum.ibis.wsc.aufgabe23;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

public class Converter extends HttpServlet{
	public void doGet(HttpServletRequest request, HttpServletResponse response)
	throws IOException, ServletException {
		try{
			response.setContentType("text/html");
		    PrintWriter out = response.getWriter();
		    File xmlFile = new File(getServletContext().getRealPath("/WEB-INF/premiumCustomers.xml"));
			File xsltFile = new File(getServletContext().getRealPath("/WEB-INF/customers.xslt"));
			Source xmlSource = new StreamSource(xmlFile);
			Source xsltSource = new StreamSource(xsltFile);
			Result result = new StreamResult(out);
			TransformerFactory transFact = TransformerFactory.newInstance();
			Transformer trans = transFact.newTransformer(xsltSource);
			trans.transform(xmlSource, result);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
}
